﻿using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using UniMana.Data;
using UniMana.Utils.Controls;
using UniMana.Utils.Data;

namespace UniMana.Win.Tool
{
    public partial class FrmSoftware_RequestForm_AddSubtitle : DevExpress.XtraEditors.XtraForm
    {
        private DBMain m_dbTraining = new DBMain();
        private bds m_bds;

        public FrmSoftware_RequestForm_AddSubtitle()
        {
            InitializeComponent();
        }

        private void FrmSoftware_RequestForm_AddSubtitle_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {
            m_bds = new bds();
            m_bds.DataSource = m_dbTraining.m_DCSave.Catalogue_RuleNameVis.GetAllData();
            if (m_bds.Count > 0)
                gctView.DataSource = m_bds;
        }

        private void xucBar2_btnAddNew_Click(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            m_bds.AddNew();
        }

        private void xucBar2_btnDelete_Click(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            xucBar2.dlg.Close();
            DialogResult result = new DialogResult();
            result = XtraMessageBox.Show("Bạn có muốn xóa tiêu đề đang chọn", "Thông Báo", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                m_bds.DeleteCurrent();
                this.xucBar2_btnSave_Click(sender, e);          
            }
        }

        private void xucBar2_btnSave_Click(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            xucBar2.dlg.Close();
            this.Validate();
            this.Validate();
            for (int i = 0; i < grvView.RowCount; i++)
            {
                if (grvView.GetRowCellValue(i, gclName) == null)
                {
                    XtraMessageBox.Show("Chưa nhập tên tiêu đề");
                    return;
                }
            }
            this.Save(m_bds, m_dbTraining.m_DCSave, false);
            XtraMessageBox.Show("Đã lưu thay đổi", "Thông báo");
        }
    }
}
